<!--
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				WeeklyTSSearch.jsp
  //	TITLE:				Search weekly Time Sheet sum
  //	BY:					Beyes Xia
  //	DATE:				2004-4-15 9:29
  // --------------------------------------------------------------
-->
<%@ include file="../tssheader.jsp" %>
<SCRIPT Language="Javascript" SRC="<%=contextPath%>/tss/weeklytimesheet/Calendar1-821.js"></script>
<script language="JavaScript1.1">
function mySubmit()
{
    if(checkDate(fm.date_from) && checkDate(fm.date_to) && checkFromTO()) 
	{
		fm.submit();
	}
}

function tss_calendar(obj)
{
   var today = new Date();
   show_calendar('fm.'+obj, today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function checkDate(object)
{
    var obj=object;
    var d = obj.value;
    
    var d1 = obj.name;
    
    if (obj.value==null||obj.value.length==0) 
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}
    if (obj.value!=null && obj.value.length!=10) 
	{
       alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (d.substring(4,5)!="-" || d.substring(7,8)!="-")
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    var day = d.substring(8,10);
    var month = d.substring(5,7);
    var year = d.substring(0,4);
    if (day==null || isNaN(day))
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    if (month==null || isNaN(month))
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    if (year==null || isNaN(year))
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    if (day < 1 || day > 31)
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    if (month < 1 || month > 12)
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31)
    {
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
    }
    if (month == 2)
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) 
        {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
        }
    }
    return true;
}
function checkFromTO()
{
	if(fm.date_from.value.length!=0 && fm.date_to.value.length!=0 && fm.date_from.value>fm.date_to.value)
	{
		alert("Date From must be earlier than Date To");
		return false;
	}
        return true;
}
</script>

<body>
<h2>Time Sheet Weekly Sum Search</h2>

<form id=fm method=post action='<%=contextPath%>/servlet/tss.weeklytimesheet.WeeklyTSSearch' >
<input type=hidden name='staff_no' value='<%= user.getStaff_id()%>'>
<input type=hidden name='user_name' value='<%= user.getUser_name()%>'>

<table>
<tr>
	<td>Date From:</td>
	<td>
		<input type=text name='date_from' maxlength=10  align='left'>
		<input type=button name=but_cal_from onClick="tss_calendar('date_from');" value='...'>(YYYY-MM-DD)*
	</td>
</tr>
<tr>
	<td>Date To:</td>
	<td>
		<input type=text name='date_to' maxlength=10  align='left'>
		<input type=button name=but_cal_to onClick="tss_calendar('date_to');" value='...'>(YYYY-MM-DD)*
	</td>
</tr>
</table>
<br>
<hr>
<p>
  <INPUT type=button value=Search onclick='mySubmit()' >
  <INPUT type=reset  value=Cancel >
</p>
</form>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>


